package com.leapp.sk.ui.adapter
import android.app.Activity
import android.content.Intent
import android.view.View
import com.example.baselibrary.db.dao.GroupDao
import com.example.baselibrary.db.table.GroupTable
import com.example.mvp.adapter.BaseLibAdapter
import com.example.mvp.binder.BaseDataBinder
import com.leapp.sk.R
import com.leapp.sk.bean.ClassDetialDataEntity
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.ui.activity.classs.ClassMemberActivity
import com.leapp.sk.ui.activity.im.GroupChatActivity
import com.example.util.finallist.CLASS_ID
import com.example.util.finallist.GROUP_NAME
import com.example.util.finallist.MESSAGE_LIST_ID
import com.leapp.sk.viewdelegate.adapter.personal.ContanctAdapterDelegate


/**
 * 联系人
 * @author  chaohaipeng  on 2018/8/21.
 */
class ContanctAdapter(context: Activity, mlist: List<ClassDetialDataEntity>) : BaseLibAdapter<ContanctAdapterDelegate, ClassDetialDataEntity>(context, mlist){

    /**
     * 数据
     */
    val mList = mlist
    /**
     * 上下文
     */
    val mContext = context

    override fun bindEvenListener(viewDelegate: ContanctAdapterDelegate?, position: Int) {
        val get = mList.get(position)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            val intent: Intent = Intent(mContext, ClassMemberActivity::class.java)
            intent.putExtra(CLASS_ID, get.classId)
            mContext.startActivity(intent)
        }, R.id.ll_ac_member_num)

        viewDelegate?.setOnClickListener(View.OnClickListener {
            val intent: Intent = Intent(mContext, GroupChatActivity::class.java)
            intent.putExtra(GROUP_NAME, get.className)
            intent.putExtra(MESSAGE_LIST_ID, get.groupId)
            mContext.startActivity(intent)
        }, R.id.ll_ac_class_group)
    }

    override fun notifyView(viewDelegate: ContanctAdapterDelegate?, position: Int) {
        val get = mList.get(position)
        val groupTable = GroupTable()
        groupTable.groupId = get?.groupId
        groupTable.groupNick = get?.className
        groupTable.groupAvatar = ""
        GroupDao.getInstance().updateGroup(groupTable)
        GroupDao.getInstance().updateCount(get?.groupId, get.total)
        viewDelegate?.setClassName(get)
        viewDelegate?.initTechere(mContext,mList.get(position).teacherList)
        viewDelegate?.initClassMember(mContext,mList.get(position).parentList,mList.get(position).total)
    }

    override fun getDelegateClass(): Class<ContanctAdapterDelegate> {
        return ContanctAdapterDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }
}